package org.ibase4j.service;

import java.util.Map;

import org.ibase4j.core.base.BaseService;
import org.ibase4j.model.PlatProEvent;
import org.ibase4j.model.PlatProUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;

@Service
@CacheConfig(cacheNames = "PlatEvent")
public class PlatProEventService extends BaseService<PlatProEvent> {
	@Autowired
	private PlatProUserService platProUserService;

	public Page<PlatProEvent> query(Map<String, Object> params) {
		Page<PlatProEvent> page = super.query(params);
		for (PlatProEvent platProEvent : page.getRecords()) {
			if (platProEvent != null) {
				Long createBy = platProEvent.getCreateBy();
				if (createBy != null) {
					PlatProUser platProUser = platProUserService.queryById(createBy);
					if (platProUser != null) {
						platProEvent.setUserName(platProUser.getUserName());
					} else {
						platProEvent.setUserName(createBy.toString());
					}
				}
			}
		}
		return page;
	}
}
